package com.course.confing;


import com.course.controller.interceptor.LoginCheckinterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private LoginCheckinterceptor loginCheckinterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginCheckinterceptor).addPathPatterns("/**").excludePathPatterns("/login");
        System.out.println("mvc方法调用");
    }
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        System.out.println("调用了此mvc方法");
        registry.addMapping("/**")
                .allowedOrigins("http://localhost:8081")  // 可以根据需要限制具体的域名
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
                .allowedHeaders("Content-Type", "Authorization", "Token")
                .allowCredentials(true)
                .maxAge(3600);
    }
}
